

var xhr;

function iniciaComet(){		
	
	xhr = createXMLHttpRequest();
	xhr.multipart = true;
	xhr.open('GET', 'NoticiasComet', true);
	xhr.onreadystatechange = function(){
	    if( this.readyState == 4 && this.status == 200 ){
	    	var xmlDoc = this.responseXML;
	        tratarMensagem(xmlDoc);
	    }
	};
	xhr.send(null);
}


function tratarMensagem(xmlDoc){

	var mensagem = pegaConteudoDaTag("mensagem",xmlDoc);
	var divNoticias = document.getElementById("comet_div");
	var divNoticia = document.createElement("div");
	divNoticia.setAttribute('class','comet_div'); 
	divNoticia.innerHTML = mensagem;
	divNoticias.appendChild(divNoticia); 
}

function pegaConteudoDaTag(nomeDaTag,xmlDoc){
	var nodeList = xmlDoc.getElementsByTagName(nomeDaTag);
	var no = nodeList.item(0);
	var conteudo = no.firstChild.data;
	return conteudo;	
}


function createXMLHttpRequest() {	
	try { return new ActiveXObject("Msxml2.XMLHTTP");    } catch(e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} 
	try { return new XMLHttpRequest();                   } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
}
